package cn.yaboya.system.service.impl;

import cn.yaboya.basic.service.Impl.BaseServiceImpl;

import cn.yaboya.basic.utils.PageList;
import cn.yaboya.system.domain.Dictionary;
import cn.yaboya.system.domain.Dictionarydetail;
import cn.yaboya.system.mapper.DictionaryMapper;
import cn.yaboya.system.mapper.DictionarydetailMapper;
import cn.yaboya.system.query.DictionarydetailQuery;
import cn.yaboya.system.service.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DictionaryServiceImpl extends BaseServiceImpl<Dictionary> implements IDictionaryService {

    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Autowired
    private DictionarydetailMapper dictionarydetailMapper;


    public PageList<Dictionarydetail> loadByIdType(DictionarydetailQuery dictionarydetailQuery) {
        List<Dictionarydetail> rows = dictionaryMapper.loadByIdType(dictionarydetailQuery);

        Integer count = dictionarydetailMapper.queryCount(dictionarydetailQuery);
        PageList data = new PageList(rows, count);

        return data;

    }
    /**
    * @Title: remove
    * @Description: 多级删除
    * @Author: LT
    * @Version: 1.0
    * @Date:  2022/6/30 17:59
    * @Parameters: [id]
    * @Return void
    */
    public void remove(Long id){
        System.out.println(id);
        if (dictionarydetailMapper.loadAllType(id)!=null){
            List<Dictionarydetail> list = dictionarydetailMapper.loadAllType(id);

            Long[] ids = new Long[list.size()];
            int i = 0;
            for (Dictionarydetail dictionarydetail : list) {
                Long id1 = dictionarydetail.getId();
                ids[i] = id1;
                i++;
            }

            dictionarydetailMapper.batchRem(ids);
        }

        dictionaryMapper.remove(id);
    }

}
